Imports System
Imports System.Xml

Public Class VoidMsg
    Inherits BaseMsg

    Protected m_rpttype As String ' 0 = Submit, 2 = Accept, 3 = Decline, 6 = Trade Report Cancel
    Protected m_transtype As String ' 1=void
    Protected m_lastpx As String ' trade price per contract
    Protected m_lastqty As String ' trade quantity

    Protected m_execid As String


    '<FIXML v="4.4" s="20040109" r="20030618">
    '<TrdCaptRpt RptID="VOIDRPTID1013-1" TransTyp="1" RptTyp="0" LastPx="50.50" LastQty="3000" ExecID="96887">
    '<Hdr TID="NYMEX" TSub="cpcapi"/>
    '</TrdCaptRpt>
    '</FIXML>
    '

    '<FIXML v="4.4" s="20040109" r="20030618">
    '<TrdCaptRptAck RptID="VOIDRPTID1013-1" TransTyp="1" TrdRptStat="0" ExecID="96887" ExecTyp="H">
    '<Hdr SID="NYMEX" SSub="cpcapi"/>
    '</TrdCaptRptAck>
    '</FIXML>

#Region "properties"

    Public Property ReportType() As String
        Get
            Return m_rpttype
        End Get
        Set(ByVal Value As String)
            m_rpttype = Value
        End Set
    End Property

    Public Property TransType() As String
        Get
            Return m_transtype
        End Get
        Set(ByVal Value As String)
            m_transtype = Value
        End Set
    End Property

    Public Property TradePrice() As String
        Get
            Return m_lastpx
        End Get
        Set(ByVal Value As String)
            m_lastpx = Value
        End Set
    End Property

    Public Property TradeQuantity() As String
        Get
            Return m_lastqty
        End Get
        Set(ByVal Value As String)
            m_lastqty = Value
        End Set
    End Property

    Public Property ExecID() As String
        Get
            Return m_execid
        End Get
        Set(ByVal Value As String)
            m_execid = Value
        End Set
    End Property

#End Region

    Public Sub New(ByVal exec As String)
        IsCPC = False
        ReportType = "0"
        TransType = "1"
        ExecID = exec
        RequestType = "TrdCaptRpt"
        ResponseType = "TrdCaptRptAck"
    End Sub

    Protected Overrides Function RequestMsg(ByRef XmlW As XmlTextWriter) As Boolean

        m_excludes = New ExcludeFields(Me.ProductID)

        XmlW.WriteStartElement("FIXML")
        XmlW.WriteAttributeString("v", "4.4")
        XmlW.WriteAttributeString("s", "20040109")
        XmlW.WriteAttributeString("r", "20030618")

        '<TrdCaptRpt RptID="VOIDRPTID1013-1" TransTyp="1" RptTyp="0" LastPx="50.50" LastQty="3000" ExecID="96887">

        XmlW.WriteStartElement("TrdCaptRpt")
        XmlW.WriteAttributeString("RptID", UID)
        XmlW.WriteAttributeString("TransTyp", TransType)
        XmlW.WriteAttributeString("RptTyp", ReportType)

        XmlW.WriteAttributeString("LastPx", TradePrice)
        XmlW.WriteAttributeString("LastQty", TradeQuantity)
        XmlW.WriteAttributeString("ExecID", ExecID)

        '            <Hdr TID="NYMEX" TSub="cpcapi"/>
        XmlW.WriteStartElement("Hdr")
        XmlW.WriteAttributeString("TID", "NYMEX")
        XmlW.WriteAttributeString("TSub", "cpcapi")
        XmlW.WriteEndElement()

        If TransType = "1" Then
            ' this is a cancel request, we don't need more data
            XmlW.WriteEndElement()   'TrdCaptRpt
            XmlW.WriteEndElement()   'FIXML
            Return True
        End If

        If LastMMY = "" Then
            ' for non-strip:
            '		<Instrmt ID="LC" CFI="OPXXXX" MMY="200612" Strk="25.00" TmUnit="mo" />
            XmlW.WriteStartElement("Instrmt")
            WriteOrExclude(XmlW, "ID", m_prodid)
            WriteOrExclude(XmlW, "CFI", FirstCFI)
            WriteOrExclude(XmlW, "MMY", FirstMMY)
            WriteOrExclude(XmlW, "Strk", FirstStrikePrice)
            WriteOrExclude(XmlW, "TmUnit", FirstTmUnit)
            XmlW.WriteEndElement()
        Else
            ' for strip-trade:
            '            <Instrmt ID="LN" CFI="M" TmUnit="mo"/>
            '            <TrdLeg>
            '                  <Leg CFI="OPXXXX" MMY="200802" Strk="5.00"/>
            '            </TrdLeg>
            '            <TrdLeg>
            '                  <Leg CFI="OPXXXX" MMY="200806" Strk="5.00"/>
            '            </TrdLeg>
            XmlW.WriteStartElement("Instrmt")
            WriteOrExclude(XmlW, "ID", m_prodid)
            WriteOrExclude(XmlW, "CFI", "M")
            WriteOrExclude(XmlW, "TmUnit", FirstTmUnit)
            XmlW.WriteEndElement()

            XmlW.WriteStartElement("TrdLeg")
            XmlW.WriteStartElement("Leg")
            WriteOrExclude(XmlW, "CFI", FirstCFI)
            WriteOrExclude(XmlW, "MMY", FirstMMY)
            WriteOrExclude(XmlW, "Strk", FirstStrikePrice)
            XmlW.WriteEndElement()
            XmlW.WriteEndElement()

            XmlW.WriteStartElement("TrdLeg")
            XmlW.WriteStartElement("Leg")
            WriteOrExclude(XmlW, "CFI", LastCFI)
            WriteOrExclude(XmlW, "MMY", LastMMY)
            WriteOrExclude(XmlW, "Strk", LastStrikePrice)
            XmlW.WriteEndElement()
            XmlW.WriteEndElement()
        End If

        m_buyer.BuildXML(XmlW)
        m_seller.BuildXML(XmlW)

        XmlW.WriteEndElement()   'TrdCaptRpt
        XmlW.WriteEndElement()   'FIXML

        Return True
    End Function


End Class
